﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lm.Common.ExtensionMethods;

namespace Lm.Common.Auth.Role
{
    class RoleDal
    {
        public Model.Role GetByRoleCode(string roleCode)
        {
            if (roleCode.IsNullOrBlank())
            { throw new Exception("角色编号不能为空"); }
            using (var tran = new System.Transactions.TransactionScope())
            {
                var helper = Lm.Common.Auth.DAL.DALFactory.Create();
                if (helper.IsSingle<Model.Role>(t => t.RoleCode == roleCode) == false)
                { throw new Exception("角色不存在"); }
                var role = helper.GetSingle<Model.Role>(t => t.RoleCode == roleCode);
                tran.Complete();
                return role;
            }
        }
    }
}
